package com.xm.dao.background;

import com.xm.entity.CommodityServe;
import com.xm.exception.SqlErrorException;
import com.xm.util.BaseUtil;
import org.intellij.lang.annotations.Language;

import java.sql.SQLException;

/**
 * 商品服务Dao
 * @author 康文程
 * @date 2024-1-20
 */
public class CommodityServeDao extends BaseUtil {
    /**
     * 根据商品服务对象修改商品服务
     *
     * @param commodityServe 商品服务对象
     * @return boolean true修改成功
     * @throws SqlErrorException SQL执行异常
     */
    public boolean updateByCommodityServe(CommodityServe commodityServe) throws SqlErrorException {
        @Language("SQL")
        String sql = "UPDATE commodity_serve SET is_self_employed = ?, is_mi_shipments = ?, is_return = ?, " +
                "is_price_protection = ?, is_shipping_instructions = ?, is_company_information = ?, " +
                "is_after_sales = ? WHERE commodity_id = ?";
        try {
            executeUpdate(sql, commodityServe.getIsSelfEmployed(), commodityServe.getIsMiShipments(),
                    commodityServe.getIsReturn(), commodityServe.getIsPriceProtection(),
                    commodityServe.getIsShippingInstructions(), commodityServe.getIsCompanyInformation(),
                    commodityServe.getIsAfterSales(), commodityServe.getCommodityId());
            return true;
        } catch (SQLException e) {
            throw new SqlErrorException("修改商品服务失败", e);
        }
    }
    /**
     * 根据商品服务对象修改商品服务
     *
     * @param commodityId 商品Id
     * @return boolean true修改成功
     * @throws SqlErrorException SQL执行异常
     */
    public boolean addCommodityServe(Integer commodityId) throws SqlErrorException {
        @Language("SQL")
        String sql = "INSERT INTO `commodity_serve` (commodity_id) values(?)";
        return executeUpdate(sql,commodityId) != 0;
    }
}
